package escom.dds.gestionaralumno.controller;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

import escom.dds.gestionaralumno.bussines.AlumnoBs;
import escom.dds.modelo.Alumno;

public class GestionarAlumnoCtrl extends ActionSupport implements
		ModelDriven<Alumno> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private AlumnoBs alumnoBs;
	private Alumno model;
	private List<Alumno> listAlumnos;

	private Integer idSel;

	public String index() {
		listAlumnos = alumnoBs.findAll();
		return "index";
	}

	public String editNew() {
		return "editNew";
	}

	public String create() {
		alumnoBs.save(model);
		return index();
	}

	public String edit() {
		return "edit";
	}

	public String update() {
		alumnoBs.update(model);
		System.out.println("En update");
		return index();
	}

	public String deleteConfirm() {
		return "deleteConfirm";
	}

	public String destroy() {
		alumnoBs.delete(model);
		System.out.println("Destroyyyy");
		return index();
	}

	/**
	 * @return the idSel
	 */
	public Integer getIdSel() {
		return idSel;
	}

	/**
	 * @param idSel
	 *            the idSel to set
	 */
	public void setIdSel(Integer idSel) {
		model = new Alumno();
		if (idSel != null) {
			model.setMatricula(idSel);
			model = alumnoBs.findById(model);
		}
		this.idSel = idSel;
	}

	/**
	 * @return the alumnoBs
	 */
	public AlumnoBs getAlumnoBs() {
		return alumnoBs;
	}

	/**
	 * @param alumnoBs
	 *            the alumnoBs to set
	 */
	public void setAlumnoBs(AlumnoBs alumnoBs) {
		this.alumnoBs = alumnoBs;
	}

	/**
	 * @return the model
	 */
	public Alumno getModel() {
		return model;
	}

	/**
	 * @param model
	 *            the model to set
	 */
	public void setModel(Alumno model) {
		this.model = model;
	}

	/**
	 * @return the listAlumnos
	 */
	public List<Alumno> getListAlumnos() {
		return listAlumnos;
	}

	/**
	 * @param listAlumnos
	 *            the listAlumnos to set
	 */
	public void setListAlumnos(List<Alumno> listAlumnos) {
		this.listAlumnos = listAlumnos;
	}

}
